package jnpf.base.util;

import jnpf.constant.MsgCode;
import jnpf.database.model.dbfield.JdbcColumnModel;
import jnpf.database.model.dbtable.JdbcTableModel;
import jnpf.database.model.entity.DbLinkEntity;

import java.util.List;

/**
 * 打印模板-工具类
 *
 * @author JNPF开发平台组 YY
 * @version V3.2.0
 * @copyright 引迈信息技术有限公司
 * @date 2019年9月30日
 */
public class PrintDevUtil {

    /**
     * 获取字段注释
     * [1]:表注释 [2]:字段注释
     */
    public static String[] getTableColumnComment(DbLinkEntity dbLinkEntity, String table, String columnName){
        try {
            JdbcTableModel jdbcTableModel = new JdbcTableModel(dbLinkEntity, table);
            String tableComment = jdbcTableModel.getComment();
            String columnComment = "";
            List<JdbcColumnModel> columnList = jdbcTableModel.getJdbcColumnModelList();
            for(JdbcColumnModel column : columnList){
                if(column.getField().equalsIgnoreCase(columnName)){
                    columnComment =  column.getComment();
                }
            }
            return new String[] {tableComment, columnComment};
        } catch (Exception e) {
            throw new RuntimeException(MsgCode.SYS038.get(), e);
        }
    }

}
